﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace BanVeXemPhim_Presentation
{
    public partial class UserControlPhim : UserControl
    {
        public UserControlPhim()
        {
            InitializeComponent();
        }
        private Bitmap _memoryBitmap;
        private Graphics _memoryGraphic;
        private PhimDTO _phim;
        private Bitmap _hinhAnhPhim;

        //Tạo sự kiện khi nhấn book vé, tham số của hàm chỉnh sau.
        public delegate void ClickBook(PhimDTO phim);
        public event ClickBook ClickEvent;

        public PhimDTO Phim
        {
            get { return _phim; }
            set { _phim = value; }
        }

        public Bitmap HinhAnhPhim
        {
            get { return _hinhAnhPhim; }
            set
            {
                _hinhAnhPhim = value;

            }
        }

        private void UserControlPhim_Load(object sender, EventArgs e)
        {
            _memoryBitmap = new Bitmap(this.Width, this.Height);
            _memoryGraphic = Graphics.FromImage(this._memoryBitmap);
        }

        private void UserControlPhim_Paint(object sender, PaintEventArgs e)
        {
            if (_phim.DataHinh != null)
            {
                if(_hinhAnhPhim==null)
                {
                    MemoryStream stream=new MemoryStream(_phim.DataHinh);
                    _hinhAnhPhim=new Bitmap(stream);
                }
                _memoryGraphic.DrawImage(_hinhAnhPhim, 0, 0, Width, Height - 20);
            }
            e.Graphics.DrawImage(this._memoryBitmap,0,0);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(ClickEvent!=null)
            {
                ClickEvent(Phim);
            }
        }
    }
}
